package com.suneast.suneaststore.modules.personal.order.adapter;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.suneast.suneaststore.R;
import com.suneast.suneaststore.bean.personal.order.ListBean;
import com.suneast.suneaststore.modules.personal.order.OrderHandler;

class VHFast extends BaseViewHolder {
    private TextView tvMerchant;
    private TextView tvStatus;
    private TextView tvFastOrderInfo;
    private TextView tvOrderPaymentInfo;
    private RecyclerView rvGoods;
    private FastGoodsAdapter adapter;
    VHFast(View itemView, int status, int listType) {
        super(itemView, status, listType);
        tvMerchant = itemView.findViewById(R.id.tv_merchant);
        tvStatus = itemView.findViewById(R.id.tv_status);
        rvGoods = itemView.findViewById(R.id.rv_goods);
        tvFastOrderInfo = itemView.findViewById(R.id.tv_fast_order_info);
        tvOrderPaymentInfo = itemView.findViewById(R.id.tv_order_payment_info);
        buttons[0] = itemView.findViewById(R.id.btn_left);
        buttons[1] = itemView.findViewById(R.id.btn_right);
        rvGoods.setLayoutManager((LinearLayoutManager) itemView.getTag());
        adapter = new FastGoodsAdapter();
        rvGoods.setAdapter(adapter);
        constructors[listType].construct(buttons, status);
    }

    @Override
    void updateData(ListBean.Order order) {
        tvMerchant.setText(order.getMerchname());
        tvStatus.setText(order.getStatus_title());
        rvGoods.setLayoutManager((LinearLayoutManager) itemView.getTag());
        rvGoods.setAdapter(adapter);
        adapter.setList(order.getGoods());

//        if (order.getStatus() != OrderHandler.ORDER_CANCELED) {
//            String info = tvOrderPaymentInfo.getContext().getString(R.string.fast_order_payment_info,
//                    order.getStatus() == OrderHandler.ORDER_UNPAID ? "待付" : "实付",
//                    order.getPrice());
//            SpannableString spannableString = new SpannableString(info);
//            spannableString.setSpan(new ForegroundColorSpan(Color.RED),
//                    info.lastIndexOf(" "), info.length(),
//                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//            tvOrderPaymentInfo.setText(spannableString);
//        } else {
//            tvOrderPaymentInfo.setText(tvOrderPaymentInfo.getContext().getString(R.string.order_already_canceled));
//        }
        tvFastOrderInfo.setText(R.string.fast_order);
    }
}